package testLayer;

import static org.junit.Assert.*;
import modelLayer.OrderLine;
import modelLayer.SalesOrder;

import java.util.Date;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class SalesOrderTest {
	
	private Date       date;
	private SalesOrder salesOrder;
	
	@Before
	public void setUp() {
		
		this.date = new Date();
		this.salesOrder = new SalesOrder();
		this.salesOrder.setOrderID(1234);
		
	}

	@After
	public void tearDown() throws Exception {
		
		
		
	}
		
	@Test
	public void testGetOrderIDSuccess() {
		
		assertEquals(1234, this.salesOrder.getOrderID());
		
	}
	
	@Test
	public void testGetOrderIDFails() {
		
		assertNotSame(4321, this.salesOrder.getOrderID());
		
	}
	
	@Test
	public void testSetOrderIDSuccess() {
		
		this.salesOrder.setOrderID(4321);
		assertEquals(4321, this.salesOrder.getOrderID());
		
	}
	
	@Test
	public void testSetOrderIDFails() {
		
		this.salesOrder.setOrderID(4321);
		
	}
	
	/**
	 * Get date is getting todays date therefore further testing
	 * is redundant
	 */
	@Test
	public void testGetDate() {
		
		assertEquals(this.date, this.salesOrder.getDate());
		
	}
	
	@Test
	public void testSetDate() {
		
		this.salesOrder.setDate();
		assertEquals(this.date, this.salesOrder.getDate());
		
	}
	
	@Test
	public void testAddOrderLine() {
		
		OrderLine ol = new OrderLine();
		assertTrue(this.salesOrder.addOrderLine(ol));
		assertFalse(this.salesOrder.addOrderLine(ol));
		assertEquals(this.salesOrder, ol.getSalesOrder());
		assertTrue(this.salesOrder.getOrderLines().contains(ol));
		
	}
	
	@Test
	public void testAddOrderLines() {
		
		OrderLine ol = new OrderLine();
		this.salesOrder.addOrderLine(ol);
		OrderLine ol1 = new OrderLine();
		this.salesOrder.addOrderLine(ol1);
		assertEquals(this.salesOrder, ol1.getSalesOrder());
		assertTrue(this.salesOrder.getOrderLines().contains(ol1));
		assertEquals(this.salesOrder, ol.getSalesOrder());
		assertTrue(this.salesOrder.getOrderLines().contains(ol));
		
	}
	
}
